import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/error_widget.dart';
import 'package:s_mankey/ui/widget/loading_widget.dart';
import 'package:s_mankey/ui/widget/unlogin_nav.dart';

class SystemNotice extends StatefulWidget {

  final arguments;

  SystemNotice({this.arguments});

  @override
  _SystemNotice createState() => _SystemNotice();
}

class _SystemNotice extends State<SystemNotice> {

  var datas;
  Map<String, dynamic> nextOptions = Map();

  @override
  void initState() {
    UnLoginNav(context).unLogin();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar: AppBar(
        elevation: 0,
        title: Text('消息列表'),
      ),
      body: FutureBuilder(future: SmonkeysRepository.fetchNotifyList(),builder:
    (BuildContext context, AsyncSnapshot snapshot) {

    /// 请求中
    if (snapshot.connectionState != ConnectionState.done) {
    return LoadingWidget();
    }
    /// 请求结束
    if (snapshot.hasError) {
    // 请求失败，显示错误
    return unLoginErrorTip(errorTip: snapshot.error.toString(),context: context,);
    }

    datas = snapshot.data;
    // 请求成功，显示数据
    return ListView.builder(itemCount: datas.length,itemBuilder: (BuildContext context, int index){
        return GestureDetector(onTap: (){
          nextOptions['id'] =  datas[index]['belong_notify_id'];
          nextOptions['cid'] =  datas[index]['cid'];
          Navigator.pushNamed(context, RouterName.systemMsgDetail,arguments: nextOptions);
        },child: Container(
          decoration: BoxDecoration(border: Border(bottom: BorderSide(color: AppColor.dividerColor))),
          padding: EdgeInsets.all(10),
          child:
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.only(right: 10),
                child: ClipOval(
                  child: Image.network(
                    "https://dss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=251289958,1860898046&fm=26&gp=0.jpg",
                    height: 42,
                    width: 42,
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              Expanded(child:
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Padding(
                      padding: const EdgeInsets.only(right: 8),
                      child: Text(datas[index]['template_name'], style: TextStyle(fontSize: AppFontSize.Size16),),
                    ),
                    Container(
                      width: 80 ,child: Text(datas[index]['create_time'], style: TextStyle(fontSize: AppFontSize.Size14,color: Color(0xff747474)),overflow: TextOverflow.clip,),),
                  ],),
                Text(datas[index]['message'], style: TextStyle(fontSize: AppFontSize.Size14)),
              ],)),
            ],),));
      });}),
    );
  }

}